package com.logistics.pick.entity.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.logistics.inventory.entity.model.UpdStation;
import com.logistics.pick.entity.model.PickContainerSave;
import com.logistics.utils.tool.DateUtils;
import com.logistics.utils.bean.UserBean;
import com.logistics.utils.tool.StringUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 拣配托盘
 * </p>
 *
 * @author yunjian.ban
 * @since 2024-06-27
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("lgs_pick_container")
public class PickContainer implements Serializable {

    private static final long serialVersionUID = 1L;

    // id
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    // 拣配单
    private Integer pick;

    //状态：0:拣配中,10:拣配完成,20:配送中,30:配送完成
    private Integer status;

    // 托盘
    private String container;

    // 托盘层级
    private Integer containerLevel;

    // 父托盘（即最下层托盘）
    private String fatherContainer;

    // 班组编号
    private String wcCode;

    // 班组名称
    private String wcName;

    // 站点
    private String station;

    // 创建人组织编码
    private String createOrgCode;

    // 创建人部门编码
    private String createDepCode;

    // 创建人
    private String creator;

    // 创建时间
    private Date createTime;

    // 修改人
    private String updater;

    // 修改时间
    private Date updateTime;

    @TableField(select = false)
    private List<PickContainer> children;

    @TableField(select = false)
    private String type;

    @TableField(select = false)
    private String location;

    public PickContainer(){

    }

    public PickContainer(PickContainerSave save){
        this.id = StringUtils.isNotNull(save.getId()) ? Integer.parseInt(save.getId()) : null;
        this.pick = StringUtils.isNotNull(save.getPick()) ? Integer.parseInt(save.getPick()) : null;
        this.status = StringUtils.isNotNull(save.getStatus()) ? Integer.parseInt(save.getStatus()) : null;
        this.container = save.getContainer();
        this.containerLevel = StringUtils.isNotNull(save.getContainerLevel()) ? Integer.parseInt(save.getContainerLevel()) : null;
        this.fatherContainer = save.getFatherContainer();
        this.station = save.getStation();
        this.createOrgCode = save.getCreateOrgCode();
        this.createDepCode = save.getCreateDepCode();
        this.creator = save.getCreator();
        this.createTime = new Date();
        this.updater = save.getUpdater();
        this.updateTime = new Date();
    }

    public static PickContainer build(PickContainerSave save){
        return new PickContainer(save);
    }

    public static PickContainer build(String station){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setStation(station);
        return pickContainer;
    }

    public static PickContainer build(UpdStation updStation, boolean isFlag){
        PickContainer pickContainer = new PickContainer();
        if(isFlag){
            pickContainer.setStation(updStation.getStationCode());
        }else{
            pickContainer.setContainer(updStation.getContainerCode());
        }
        pickContainer.setUpdater(updStation.getUpdater());
        pickContainer.setUpdateTime(DateUtils.stringToDateFormat(updStation.getUpdateTime(), DateUtils.YYYY_MM_DD_HH_MM_SS));
        return pickContainer;
    }

    public static PickContainer build(Integer status){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setStatus(status);
        return pickContainer;
    }

    public static PickContainer build(Integer pick, String status, String container, String station){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setPick(pick);
        pickContainer.setStatus(StringUtils.isNotNull(status) ? Integer.parseInt(status): null);
        pickContainer.setContainer(container);
        pickContainer.setStation(station);
        return pickContainer;
    }

    public static PickContainer build(Integer status, String updater){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setStatus(status);
        pickContainer.setUpdater(updater);
        pickContainer.setUpdateTime(new Date());
        return pickContainer;
    }

    public static PickContainer build(Integer pick, String status, String container, String station, UserBean userBean){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setPick(pick);
        pickContainer.setStatus(StringUtils.isNotNull(status) ? Integer.parseInt(status): null);
        pickContainer.setContainer(container);
        pickContainer.setStation(station);
        pickContainer.setContainerLevel(1);
        pickContainer.setCreateOrgCode(userBean.getOrganization());
        pickContainer.setCreateDepCode(userBean.getDep());
        pickContainer.setCreator(userBean.getAccount());
        pickContainer.setCreateTime(new Date());
        pickContainer.setUpdater(userBean.getAccount());
        pickContainer.setUpdateTime(new Date());
        return pickContainer;
    }

    public static PickContainer build(String wcCode, String wcName){
        PickContainer pickContainer = new PickContainer();
        pickContainer.setWcCode(wcCode);
        pickContainer.setWcName(wcName);
        return pickContainer;
    }
}
